From e5b2e9f4477b8dbbcf66a45abe3aced8122a3ac7 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 22 Nov 2006 09:06:24 +0000 Subject: [PATCH] Applying patch (slightly modified) from bug 8003 by AlefZet. The patch is clearly necessary, but I'm not sure if it is sufficient. Also fixed indenting. --- languages/classes/LanguageKk.php | 135 +++++++++++++++---------------- 1 file changed, 67 insertions(+), 68 deletions(-) diff --git a/languages/classes/LanguageKk.php b/languages/classes/LanguageKk.php index 71ca081df4..59cd8324f8 100644 --- a/languages/classes/LanguageKk.php +++ b/languages/classes/LanguageKk.php @@ -88,61 +88,61 @@ class KkConverter extends LanguageConverter { 'Ы' => 'ى', 'Ь' => 'ي', 'І' => 'ٴى', 'Э' => 'ە', 'Ю' => 'يۋ', 'Я' => 'يا', ); - function loadDefaultTables() { + function loadDefaultTables() { $this->mTables = array( 'kk-kz' => new ReplacementArray( $this->mLatinToCyrillic ), 'kk-tr' => new ReplacementArray( $this->mCyrillicToLatin ), 'kk-cn' => new ReplacementArray( $this->mCyrillicToArabic ), 'kk' => new ReplacementArray() ); - } - - /* - * Override function from LanguageConvertor - */ - function getPreferredVariant(){ - global $wgUser, $wgRequest, $wgTitle;; - // Additional checks: - // - There should be no conversion for Talk pages - if($wgTitle!=NULL && $wgTitle->isTalkPage()){ - return $this->mMainLanguageCode; - } - return parent::getPreferredVariant(); - } - - /* - * A function wrapper, if there is no selected variant, - * leave the link names as they were - */ - function findVariantLink( &$link, &$nt ) { - $oldlink=$link; - parent::findVariantLink($link,$nt); - if($this->getPreferredVariant()==$this->mMainLanguageCode) - $link=$oldlink; - } - - /* - * We want our external link captions to be converted in variants, - * so we return the original text instead -{$text}-, except for URLs - */ - function markNoConversion($text) { - if(preg_match("/^https?:\/\/|ftp:\/\/|irc:\/\//",$text)) - return parent::markNoConversion($text); - return $text; - } - - /* - * An ugly function wrapper for parsing Image titles - * (to prevent image name conversion) - */ - function autoConvert($text, $toVariant=false) { - global $wgTitle; - if($wgTitle->getNameSpace()==NS_IMAGE){ - $imagename = $wgTitle->getNsText(); - if(preg_match("/^$imagename:/",$text)) return $text; - } - return parent::autoConvert($text,$toVariant); - } + } + + /* + * Override function from LanguageConvertor + * Additional checks: + * - There should be no conversion for Talk pages + */ + function getPreferredVariant(){ + global $wgTitle; + if( is_object( $wgTitle ) && $wgTitle->isTalkPage()) { + return $this->mMainLanguageCode; + } + return parent::getPreferredVariant(); + } + + /* + * A function wrapper, if there is no selected variant, + * leave the link names as they were + */ + function findVariantLink( &$link, &$nt ) { + $oldlink=$link; + parent::findVariantLink($link,$nt); + if($this->getPreferredVariant()==$this->mMainLanguageCode) + $link=$oldlink; + } + + /* + * We want our external link captions to be converted in variants, + * so we return the original text instead -{$text}-, except for URLs + */ + function markNoConversion($text, $noParse=false) { + if($noParse || preg_match("/^https?:\/\/|ftp:\/\/|irc:\/\//",$text)) + return parent::markNoConversion($text); + return $text; + } + + /* + * An ugly function wrapper for parsing Image titles + * (to prevent image name conversion) + */ + function autoConvert($text, $toVariant=false) { + global $wgTitle; + if($wgTitle->getNameSpace()==NS_IMAGE){ + $imagename = $wgTitle->getNsText(); + if(preg_match("/^$imagename:/",$text)) return $text; + } + return parent::autoConvert($text,$toVariant); + } /** * It translates text into variant, specials: @@ -159,7 +159,7 @@ class KkConverter extends LanguageConverter { $matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE); $m = array_shift($matches); - $ret = strtr($m[0], $this->mTables[$toVariant]); + $ret = $this->mTables[$toVariant]->replace( $m[0] ); $mstart = $m[1]+strlen($m[0]); foreach($matches as $m) { $ret .= substr($text, $mstart, $m[1]-$mstart); @@ -174,39 +174,38 @@ class KkConverter extends LanguageConverter { class LanguageKk extends LanguageKk_kz { - function __construct() { - global $wgHooks; + function __construct() { + global $wgHooks; parent::__construct(); - $variants = array('kk', 'kk-kz', 'kk-tr', 'kk-cn'); - $variantfallbacks = array( - 'kk' => 'kk-kz', - 'kk-kz' => 'kk-kz', + $variants = array('kk', 'kk-kz', 'kk-tr', 'kk-cn'); + $variantfallbacks = array( + 'kk' => 'kk-kz', + 'kk-kz' => 'kk-kz', 'kk-tr' => 'kk-tr', 'kk-cn' => 'kk-cn' - ); + ); - $this->mConverter = new KkConverter( $this, 'kk', $variants, $variantfallbacks ); - $wgHooks['ArticleSaveComplete'][] = $this->mConverter; - } + $this->mConverter = new KkConverter( $this, 'kk', $variants, $variantfallbacks ); + $wgHooks['ArticleSaveComplete'][] = $this->mConverter; + } function convertGrammar( $word, $case ) { $fname="LanguageKk::convertGrammar"; wfProfileIn( $fname ); - //always convert to kk-kz before convertGrammar - $w1 = $word; + //always convert to kk-kz before convertGrammar + $w1 = $word; $word = $this->mConverter->autoConvert($word, 'kk-kz'); - $w2 = $word; + $w2 = $word; $word = parent::convertGrammar( $word, $case ); - //restore encoding - if( $w1 != $w2 ) { - $word = $this->mConverter->translate($word, 'kk-tr'); - } + //restore encoding + if( $w1 != $w2 ) { + $word = $this->mConverter->translate($word, 'kk-tr'); + } wfProfileOut( $fname ); return $word; } - } ?> -- 2.20.1